<?php
/*
Bitsand - a web-based booking system for LRP events
Copyright (C) 2006 - 2009 The Bitsand Project (http://bitsand.googlecode.com/)

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

//Do not need login check for this page
$bLoginCheck = False;

include ('inc/inc_head_db.php');
include ('inc/inc_head_html.php');
$db_prefix = DB_PREFIX;

//Get list of players that have paid
if (RPG_NAME == 'LT')
	$sql = "SELECT plFirstName, " .
		"plSurname, " .
		"plBookAs, " .
		"chName, chPreferredName, chGroupSel, chGroupText, chFaction, chMonsterOnly, " .
		"bkDatePaymentConfirmed " .
		"FROM {$db_prefix}players, {$db_prefix}characters, {$db_prefix}bookings " .
		"WHERE plPlayerID = chPlayerID AND chPlayerID = bkPlayerID AND bkDatePaymentConfirmed <> '' AND bkDatePaymentConfirmed <> '0000-00-00'";
else
	$sql = "SELECT plFirstName, " .
		"plSurname, " .
		"plBookAs, " .
		"chName, chPreferredName, " .
		"bkDatePaymentConfirmed " .
		"FROM {$db_prefix}players, {$db_prefix}characters, {$db_prefix}bookings " .
		"WHERE plPlayerID = chPlayerID AND chPlayerID = bkPlayerID AND bkDatePaymentConfirmed <> '' AND bkDatePaymentConfirmed <> '0000-00-00'";

$result = ba_db_query ($link, $sql);
?>
<script src="inc/sorttable.js" type="text/javascript"></script>

<h1><?php echo TITLE?> - Bookings</h1>

<?php

if ((BOOKING_LIST_IF_LOGGED_IN && $PLAYER_ID != 0) || !BOOKING_LIST_IF_LOGGED_IN)
{
	echo "<p>The people below have confirmed IC &amp; OOC details, and been marked as paid. Click on a column header to sort by that column.</p>";
   	echo "	<table border = '1' class='sortable'><tr><th>OOC First Name</th><th>OOC Surname</th><th>IC Name</th>";

	if (LIST_GROUPS_LABEL != '')
		echo "<th>Group</th>";

	if (RPG_NAME == 'LT') { echo "<th>Faction</th>"; }

	echo "<th>Booking As</th></tr>\n";

	while ($row = ba_db_fetch_assoc ($result)) {
		echo "<tr class = 'highlight'>\n";
		echo "<td>" . htmlentities (stripslashes ($row ['plFirstName'])) . "</td>\n";
		echo "<td>" . htmlentities (stripslashes ($row ['plSurname'])) . "</td>\n";

		if ($row['chMonsterOnly'] == 0)
		{
			if (strlen($row ['chPreferredName']) == 0)
			{
				echo "<td>" . htmlentities (stripslashes ($row ['chName'])) . "</td>\n";
			}
			else
			{
				echo "<td>" . htmlentities (stripslashes ($row ['chPreferredName'])) . "</td>\n";
			}
			if (LIST_GROUPS_LABEL != '' && RPG_NAME == 'LT') {
				echo "<td>\n";
				if ($row ['chGroupText'] == 'Enter name here if not in above list' || $row ['chGroupText'] == '')
					echo htmlentities (stripslashes ($row ['chGroupSel']));
				else
					echo "Other (" . htmlentities (stripslashes ($row ['chGroupText'])) . ")";
				echo "</td>\n";
			}

			if (RPG_NAME == 'LT') { echo "<td>". htmlentities (stripslashes ($row ['chFaction'])) ."</td>"; }

		}
		else
		{
			echo "<td></td>";
			if (LIST_GROUPS_LABEL != '' && RPG_NAME == 'LT') {
				echo "<td></td>";
			}
			if (RPG_NAME == 'LT') { echo "<td></td>"; }
		}
		echo "<td>" . htmlentities (stripslashes ($row ['plBookAs'])) . "</td>\n</tr>\n";
	}

	echo "</table>";

	if (ALLOW_MONSTER_BOOKINGS) {
		$sql = "SELECT plPlayerID, " .
			"plBookAs, " .
			"bkDatePaymentConfirmed " .
			"FROM {$db_prefix}players, {$db_prefix}bookings " .
			"WHERE plBookAs LIKE 'Monster' AND plPlayerID = bkPlayerID AND bkDatePaymentConfirmed <> '' AND bkDatePaymentConfirmed <> '0000-00-00'";
		$result = ba_db_query ($link, $sql);
		$iMonsters = ba_db_num_rows ($result);
	}
	else
		$iMonsters = 0;
	$sql = "SELECT plPlayerID, " .
		"plBookAs, " .
		"bkDatePaymentConfirmed " .
		"FROM {$db_prefix}players, {$db_prefix}bookings " .
		"WHERE plBookAs LIKE 'Player' AND plPlayerID = bkPlayerID AND bkDatePaymentConfirmed <> '' AND bkDatePaymentConfirmed <> '0000-00-00'";
	$result = ba_db_query ($link, $sql);
	$iPlayers = ba_db_num_rows ($result);
	$sql = "SELECT plPlayerID, " .
		"plBookAs, " .
		"bkDatePaymentConfirmed " .
		"FROM {$db_prefix}players, {$db_prefix}bookings " .
		"WHERE plBookAs LIKE 'Staff' AND plPlayerID = bkPlayerID AND bkDatePaymentConfirmed <> '' AND bkDatePaymentConfirmed <> '0000-00-00'";
	$result = ba_db_query ($link, $sql);
	$iStaff = ba_db_num_rows ($result);
	$iTotal = $iMonsters + $iPlayers + $iStaff;
	echo "<p>\n";
	if (ALLOW_MONSTER_BOOKINGS)
		echo "$iMonsters monsters, ";
	echo "$iPlayers players, $iStaff staff. ($iTotal total)\n</p>";

}
else
{
	echo "<p>The list of bookings for this event is only available if you are logged into the system.</p>";
}
include ('inc/inc_foot.php');
?>
